package com.atguigu.ssyx;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * ClassName: CompletableFutureDemo1
 * Package: com.atguigu.ssyx
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-04
 * Time: 13:11
 */

//CompletableFuture 串行话方法
public class CompletableFutureDemo3 {

    public static void main(String[] args) {

        //创建线程池
        ExecutorService service = Executors.newFixedThreadPool(3);

        //1 任务1 返回结果 1024
        CompletableFuture<Integer> fuA = CompletableFuture.supplyAsync(() -> {
            int value = 1024;
            System.out.println("任务一 :" + value);
            return value;
        }, service);

        //2 任务2 获取任务一的返回结果
        CompletableFuture<Object> fuB = fuA.thenApplyAsync((res) -> {
            System.out.println("任务二:" + res);
            return res;
        }, service);

        //3 任务3 往下执行
        final CompletableFuture<Void> fuC = fuA.thenRunAsync(() -> {
            System.out.println("任务三 :");
        }, service);

    }

}
